/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lesson3.com.demo.ser.better;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


public class Cat extends Feline implements java.io.Serializable{
    
    public enum CatType {
        TABBY, TIGER, CALICO, HEINZE_57, UNSPECIFIED;
    }
    
    static final long serialVersionUID=1L;

    private int age;
    private String name;
    private double weight;
    private CatType type;
    
    public Cat(){
        super(4);
    }

    public CatType getType() {
        return type;
    }

    public void setType(CatType type) {
        if(type==null){
            return;
        }
        this.type = type;
    }
    
    
    
    public void meow(){
        System.out.println("Meow");
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    @Override
    public String toString() {
        String s= "Cat{legCount="+getLegCount()+", age=" + age + ", name=" + name + 
                ", weight=" + weight ;
         if(type!=null){
             s+=" and the type of cat is "+type.name();
         }else {
             s+=" unspecified cat type";
         }
         s+= '}';
         return s;
    }
    
    private void writeObject(ObjectOutputStream oos) throws IOException{
        System.out.println("In the PRIVATE method writeObject of Cat");
        oos.writeInt(getLegCount());
        oos.defaultWriteObject();
    }
    
    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException{
        System.out.println("In the PRIVATE method readObject of Cat");
        int x = ois.readInt();
        super.setLegCount(x);
        ois.defaultReadObject();
        
        if(type==null){
            type = CatType.UNSPECIFIED;
        }
    }
    
}
